package com.hualan.service.impl;

import com.hualan.bean.PanghuShop;
import com.hualan.bean.PanghuShopGoods;
import com.hualan.dao.goodsdao.impl.GoodsDaoImpl;
import com.hualan.dao.shopdao.impl.ShopDaoImpl;
import com.hualan.service.GoodsService;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public class GoodsServiceImpl implements GoodsService {
	@Override
	public int addShop(PanghuShopGoods goods) throws SQLException {
		GoodsDaoImpl goodsDao = new GoodsDaoImpl();
		ShopDaoImpl shopDao = new ShopDaoImpl();
		PanghuShop panghuShopById = shopDao.getPanghuShopById(goods.getShopId());
		System.out.println(goods);
		Optional.ofNullable(panghuShopById).orElseThrow(() -> new RuntimeException("未找到商家"));
		return goodsDao.addGoods(goods);
	}
	
	@Override
	public Map<String, Object> getGoods(Map<String, String> maps) {
		GoodsDaoImpl goodsDao = new GoodsDaoImpl();
		Map<String, Object> stringObjectMap = goodsDao.selectGoods(maps);
		return stringObjectMap;
	}
	
	@Override
	public Map<String, Object> getShopGoods(Map<String, String> maps) {
		GoodsDaoImpl goodsDao = new GoodsDaoImpl();
		Map<String, Object> stringObjectMap = goodsDao.selectShopGoods(maps);
		return stringObjectMap;
	}
	
	@Override
	public int modifyShopStatus(String goodsStatus, String goodsId) {
		GoodsDaoImpl goodsDao = new GoodsDaoImpl();
		return goodsDao.updateStatus(goodsStatus,goodsId);
	}
	
	
}
